<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Form extends Admin_Controller {

    public function __construct() {
        parent::__construct();
        //$this->data['ajax_link'] = site_url('/').'test/form';
    }

    public function index() {
        
    }

    public function edit() {
        
    }
    
    public function do_create($form_id) {
        $a = DojoForm::getFieldsValue($form_id, array('title', 'meo', 'description', 'test2_id', 'status', 'date_order', 'zone', 'price'));
        print_r($a);
        
    }

    public function add_new() {        
//                if ($this->input->post('submit_0')) {
//                    echo 'hihi';
//                    return;
//                }
        //$this->data['module_title'] = 'Liệt kê danh mục sản phẩm';
        $this->load->model('test/test1_m');
        $this->load->model('test/test4_m');

        $this->dojoform->add_model_fields('test1_m', array('title', 'meo', 'description', 'test2_id', 'status', 'date_order', 'zone', 'price'), 0);
        $this->dojoform->add_model_fields('test4_m', array('name'), 1);

        $this->dojoform->_data['ajax_link'] = site_url('/') . 'test/form';
        $data['forms'] = array();
        $data['forms'][] = $this->dojoform->render(0, array(
            'left_width' => '200',
            'form_title' => 'TEST 1 MY FORM',
            'button' => BTN_OK | BTN_CANCEL            
                ));
        $data['forms'][] = $this->dojoform->render(1, array(
            'button' => BTN_OK
                ));
        $this->template->module_title = 'Chi tiết sản phẩm';
        $this->template->ajax_link = site_url('/') . 'test/form';
        //$data['ajax_link'] = site_url('/') . 'test/form';
        //$data['ajax_link'] = site_url('/') . 'form';
        //$data = array_merge($data, $this->data);
        $this->template
                ->set_hook('TOOLBAR', 'toolbar_test', array('x' => 'y'))
                ->title('sac')
                ->build('form_add', $data);

//            $this->load->model('test/test_m');
//            $data = array(
//                'title' => 'test title',
//                'meo' => 'meo meo',
//                'description' => 'desc desc desc',
//                'test2_id' => 2,
//                'status' => 1
//            );            
//            $this->test_m->insert($data);
    }
    


    public function get_store_select($model, $field) {
        $this->load->model('test/'.$model);
        //echo $this->$model->dojo_field_store($field);
        echo $this->$model->dojo_store_gen($field);
    }

    public function get_store_grid($model='test1_m') {
        $this->load->model('test/'.$model);
        echo $this->$model->dojo_grid_store(array('test1.id','title', 'status', 'test2_id', 'test4', 'price'));
    }
    
    public function get_store_grid_user() {
        $this->load->model('test/user_m');
        echo $this->user_m->dojo_grid_store(array('users.id','username','email', 'group_id'));
    }    

    public function list_item() {
        $this->load->model('test/test1_m');
        $data['ajax_link'] = site_url('/') . 'test/form';
        $this->template
                ->set_hook('TOOLBAR', 'toolbar_grid_test1')
                ->title('Data list')
                ->build('test1_list', $data);
        //$this->dojoform->add_model_fields('test1_m',array('title','meo','description','test2_id','status','date_order','zone','price'),0);            
    }
    
    public function list_user() {
        $this->load->model('test/user_m');
        $data['ajax_link'] = site_url('/') . 'test/form';
        $this->template->module_title = 'List Users';
        $this->template
                ->set_hook('TOOLBAR', 'toolbar_grid_test1')
                ->title('Data list')
                ->build('user_grid', $data);
        //$this->dojoform->add_model_fields('test1_m',array('title','meo','description','test2_id','status','date_order','zone','price'),0);            
    }    

    function add_user() {
        $this->load->model('test/user_m');
        $this->dojoform->_data['ajax_link'] = site_url('/') . 'test/form';
        $this->dojoform->add_model_fields('user_m', array('username', 'email', 'password', 'group_id', 'theme_user_backend'), 0);
        //$this->dojoform->add_model_fields('test4_m', array('name'), 1);

        //$this->dojoform->_data['ajax_link'] = site_url('/') . 'test/form';
        $data['forms'] = array();
        $data['forms'][] = $this->dojoform->render(0, array(
            'left_width' => '200',
            'form_title' => 'ADD USER',
            'button' => BTN_OK | BTN_CANCEL            
                ));    
        $this->template->module_title = 'User management';
        $this->template->ajax_link = site_url('/') . 'test/form';        
        
        $this->template
                ->set_hook('TOOLBAR', 'toolbar_test', array('x' => 'y'))
                ->title('sac')
                ->build('form_add', $data);                
    }    

}